<template>
  <div class="app-container" style="position: relative;">
    <my-affix :offset="0" style="background: #fff;">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="盒子名称" prop="title">
          <el-input v-model="queryParams.title" placeholder="请输入盒子名称" clearable />
        </el-form-item>

        <el-form-item label="盒子id" prop="title">
          <el-input v-model="queryParams.id" placeholder="请输入盒子id" clearable />
        </el-form-item>
        <el-form-item label="商品状态" prop="status">
          <el-select v-model="queryParams.status" clearable placeholder="请选择商品状态">
            <el-option v-for="item in [
              { label: '删除', value: '4' },
              {
                value: '3',
                label: '售罄',
              },
              {
                value: '2',
                label: '下架',
              },
              {
                value: '1',
                label: '上架',
              },
            ]" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="是否玩家自制" prop="ifUserMade">
          <el-select v-model="queryParams.ifUserMade" clearable placeholder="请选择是否玩家自制">
            <el-option v-for="item in [

              {
                value: '0',
                label: '官方制作',
              },
              {
                value: '1',
                label: '玩家自制',
              },
            ]" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="是否锁箱中" prop="lockStatus">
          <el-select v-model="queryParams.lockStatus" clearable placeholder="请选择是否锁箱中">
            <el-option v-for="item in [

              {
                value: '0',
                label: '未锁箱',
              },
              {
                value: '1',
                label: '锁箱中',
              },
            ]" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="排序值" prop="sort">
        <el-input
          v-model="queryParams.sort"
          placeholder="请输入排序值"
          clearable
          
        />
      </el-form-item> -->
        <el-form-item label="商品价格" prop="price">
          <el-input v-model="queryParams.price" placeholder="请输入商品价格" clearable />
        </el-form-item>
        <el-form-item label="是否现货" prop="isYu">
          <el-input v-model="queryParams.isYu" placeholder="请输入是否现货 1现货  2 预售" clearable />
        </el-form-item>
        <!-- <el-form-item label="到货时间" prop="arriveTime">
        <el-input
          v-model="queryParams.arriveTime"
          placeholder="请输入到货时间"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="套数" prop="stock">
        <el-input
          v-model="queryParams.stock"
          placeholder="请输入套数"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="限购次数 0 不限制" prop="xgBuy">
        <el-input
          v-model="queryParams.xgBuy"
          placeholder="请输入限购次数 0 不限制"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="抽几次开启全收 0不限制" prop="xgAll">
        <el-input
          v-model="queryParams.xgAll"
          placeholder="请输入抽几次开启全收 0不限制"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="全收0关闭 1开启" prop="kgAll">
        <el-input
          v-model="queryParams.kgAll"
          placeholder="请输入全收0关闭 1开启"
          clearable
          
        />
      </el-form-item> -->
        <el-form-item label="添加时间" prop="addtime">
          <el-input v-model="queryParams.addtime" placeholder="请输入添加时间" clearable />
        </el-form-item>
        <!-- <el-form-item label="${comment}" prop="creator">
        <el-input
          v-model="queryParams.creator"
          placeholder="请输入${comment}"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="createDate">
        <el-date-picker clearable
          v-model="queryParams.createDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item> -->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
            v-hasPermi="['system:yfs_box:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
            v-hasPermi="['system:yfs_box:edit']">修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
            v-hasPermi="['system:yfs_box:remove']">删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
            v-hasPermi="['system:yfs_box:export']">导出</el-button>
        </el-col>

        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
    </my-affix>
    <el-table v-loading="loading" :data="goodsList" @selection-change="handleSelectionChange"
      @sort-change="dataListSortChangeHandle" @row-click.stop="handleEditTable">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="盒子ID" align="center" prop="id" />
      <el-table-column sortable="custom" label="是否玩家自制" align="center" prop="ifUserMade">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.ifUserMade == 1">是</el-tag>
          <el-tag v-if="scope.row.ifUserMade == 0">否</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="商品名称" align="center" prop="title" />
      <el-table-column label="商品封面图" align="center" prop="imgurl">
        <template slot-scope="scope">
          <el-image fit="cover" :src="scope.row.imgurl" style="width: 100px; height: 100px" />
        </template>
      </el-table-column>
      <el-table-column sortable="custom" label="排序值" align="center" prop="sort" />
      <el-table-column sortable="custom" label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.status == 1">上架</el-tag>
          <el-tag type="danger" v-if="scope.row.status == 2">下架</el-tag>
          <el-tag type="warning" v-if="scope.row.status == 3">待审核</el-tag>
          <el-tag type="info" v-if="scope.row.status == 4">删除</el-tag>

          <el-tag type="danger" v-if="scope.row.lockStatus">锁箱中</el-tag>
          <div v-if="scope.row.lockStatus">{{ scope.row.lockByUserId }}</div>
          
        </template>
      </el-table-column>
      <el-table-column sortable="custom" label="是否可锁箱" align="center" prop="ifCanLock">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.ifCanLock == 1">可锁箱</el-tag>
          <el-tag type="danger" v-if="scope.row.ifCanLock == 0">不可锁箱</el-tag>        
        </template>
      </el-table-column>
      <el-table-column label="商品价格" sortable="custom" align="center" prop="price" />
      <el-table-column label="是否现货" align="center" prop="isYu">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.isYu == 1">现货</el-tag>
          <el-tag v-if="scope.row.isYu == 0">预售</el-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column label="到货时间" align="center" prop="arriveTime" /> -->

      <el-table-column label="类型" align="center" prop="type">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.type == 1">打拳</el-tag>
          <el-tag type="warning" v-if="scope.row.type == 2">洞洞乐</el-tag>
          <el-tag v-if="scope.row.type == 0">一番赏</el-tag>
        </template>
      </el-table-column>
      <el-table-column sortable="custom" label="套数" align="center" prop="xgBuy" />
      <el-table-column label="限购次数" sortable="custom" align="center" prop="xgBuy">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.xgBuy == 0">不限制</el-tag>
          <span v-else> {{ scope.row.xgBuy }}</span>
        </template>
      </el-table-column>

      <el-table-column label="今日限购" sortable="custom" align="center" prop="fid">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.fid == 0">不限制</el-tag>
          <span v-else> {{ scope.row.fid }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否显示" sortable="custom" align="center" prop="ifPublicShow">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.ifPublicShow == 0">充值可见</el-tag>
          <el-tag type="warning" v-if="scope.row.ifPublicShow == 1">登录可见</el-tag>
          <el-tag type="danger" v-if="scope.row.ifPublicShow == 2">公开可见</el-tag>
        </template>
      </el-table-column>


      <el-table-column label="抽几次开启全收" align="center" prop="xgAll" sortable="custom">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.xgAll == 0">不限制</el-tag>
          <el-tag v-else>{{ scope.row.xgAll }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否区间" align="center" prop="ifInterval" sortable="custom">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.ifInterval == 0">否</el-tag>
          <el-tag v-else>是</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="产生积分" align="center" prop="ifJf" sortable="custom">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.ifJf == 0">否</el-tag>
          <el-tag v-else>是</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="产生流水" align="center" prop="ifLs" sortable="custom">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.ifLs == 0">否</el-tag>
          <el-tag v-else>是</el-tag>
        </template>
      </el-table-column>
      <el-table-column sortable="custom" prop="kgAll" label="是否全收" align="center">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.kgAll == 1">是</el-tag>
          <el-tag v-else>否</el-tag>
        </template>
      </el-table-column>
      <el-table-column sortable="custom" prop="sortType" label="是否中赏排序" align="center">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.sortType == 1">是</el-tag>
          <el-tag v-else>否</el-tag>
        </template>
      </el-table-column>
      <el-table-column sortable="custom" prop="payType" label="购买方式" align="center">
        <template slot-scope="scope">
          <el-tag :type="item == 1
              ? 'success'
              : item == 2
                ? 'warning'
                : item == 3
                  ? 'info'
                  : ''
            " v-for="item in scope.row.payType" :key="item">
            {{
              item == 1 ? "余额" : item == 2 ? "积分" : item == 3 ? "M币" : ""
            }}
          </el-tag>
          <div v-if="scope.row.payType.indexOf('3') != -1">
            {{ scope.row.menKan }}
          </div>
        </template>
      </el-table-column>
      <el-table-column sortable="custom" prop="chuan" label="串串乐" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.chuan == 0">否</el-tag>
          <el-tag type="success" v-else>{{ scope.row.chuan }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column sortable="custom" prop="kongche" label="空车" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.kongche == 0">否</el-tag>
          <el-tag type="success" v-else>{{ scope.row.kongche }}</el-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column label="收集" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.shouji == 0">否</el-tag>
          <el-tag type="success" v-else>{{ scope.row.shouji }}</el-tag>
        </template>
      </el-table-column> -->
      <el-table-column label="创建人" align="center" prop="creator" />
      <el-table-column sortable="custom" label="添加时间" align="center" prop="createDate">
        <template slot-scope="scope">
          <span>{{
            scope.row.createDate
            }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="${comment}" align="center" prop="creator" />
      <el-table-column label="${comment}" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:yfs_box:edit']">修改</el-button>
          <el-button size="mini" type="text" style="color: #d0b9dd" icon="el-icon-lock" @click="lockBox(scope.row)"
            v-hasPermi="['system:yfs_box:lock']">上锁/排位</el-button>
          <el-button size="mini" type="text" style="color: #e6a23c" icon="el-icon-aim" @click="handlequjian(scope.row)"
            v-hasPermi="['system:yfs_box:qujian']">中奖区间</el-button>

          <el-button type="text" size="small" style="color: #67c23a" icon="el-icon-circle-plus-outline"
            v-hasPermi="['system:yfs_goods:add']" @click="handleEditTable(scope.row)">添加商品</el-button>

          <el-button type="text" size="small" style="color: #909399" icon="el-icon-document-copy"
            v-hasPermi="['system:yfs_box:copy']" :loading="up_end" @click="copyBox(scope.row.id)">复制盒子</el-button>

          <!-- <el-button
            type="text"
            size="small"
            icon="el-icon-edit"
            @click="handleLookTable(scope.row)"
            >查看商品</el-button
          > -->

          <el-button size="mini" type="text" style="color: #f78989" icon="el-icon-delete"
            @click="handleDelete(scope.row)" v-hasPermi="['system:yfs_box:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改商品信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-button v-if="form.id == null" style="margin-bottom: 20px" type="primary" @click="importExcel">快捷导入</el-button>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="分类id" prop="fid">
          <el-select v-model="form.fid" placeholder="请选择">
            <el-option
              v-for="item in listFl"
              :key="item.title"
              :label="item.title"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="商品名称" prop="title">
          <el-input v-model="form.title" placeholder="请输入商品名称" />
        </el-form-item>

        <el-form-item label="是否上架" prop="status">
          <el-radio-group v-model.number="form.status">
            <el-radio :label="1">上架</el-radio>
            <el-radio :label="2">下架</el-radio>
            <el-radio :label="3">售罄</el-radio>
            <el-radio :label="4">删除</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="商品封面图" prop="imgurl">
          <image-upload :limit="1" v-model="form.imgurl" />
        </el-form-item>
        <el-form-item label="排序值" prop="sort">
          <el-input-number v-model="form.sort" controls-position="right" :min="0" :max="9999" />
        </el-form-item>
        <el-form-item label="商品价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入商品价格" />
        </el-form-item>
        <el-form-item label="是否现货" prop="isYu">
          <el-switch v-model.number="form.isYu" active-color="#13ce66" inactive-color="#F4F4F5" :active-value="1"
            :inactive-value="0">
          </el-switch>
          <!-- <el-input
            v-model="form.isYu"
            placeholder="请输入是否现货 1现货  2 预售"
          /> -->
        </el-form-item>
        <!-- <el-form-item label="到货时间" prop="arriveTime">
          <el-date-picker
            v-model="form.arriveTime"
            type="date"
            placeholder="选择到货时间"
          >
          </el-date-picker>

        </el-form-item> -->
        <!--
        <el-form-item label="商品描述" prop="desc">
          <el-input v-model="form.desc" placeholder="请输入商品描述" />
        </el-form-item> -->
        <!-- <el-form-item label="显示按钮" prop="desc">
          <template>
            <el-tag
              :key="tag"
              v-for="tag in form.dynamicTags"
              closable
              :disable-transitions="false"
              @close="handleClose(tag)"
            >
              {{ tag }}
            </el-tag>
            <el-input
              class="input-new-tag"
              v-if="inputVisible"
              v-model="inputValue"
              ref="saveTagInput"
              size="small"
              
              @blur="handleInputConfirm"
            >
            </el-input>
            <el-button
              v-else
              class="button-new-tag"
              size="small"
              @click="showInput"
              >+ 抽数按钮</el-button
            >
            <el-input
              v-if="form.ifxg_buy"
              v-model="form.ifxg_btn_num"
              placeholder="抽几次全收"
            ></el-input>
          </template>
        </el-form-item> -->
        <el-form-item label="套数" prop="stock">
          <el-input v-model="form.stock" placeholder="请输入套数" />
        </el-form-item>

        <el-form-item label="抽赏类型" prop="type">
          <el-radio-group v-model.number="form.type">
            <el-radio :label="0">双随机</el-radio>
            <el-radio :label="1">打拳</el-radio>
            <el-radio :label="2">洞洞乐</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="限购次数" prop="xgBuy">
          <!-- <el-input
            v-model="form.xgBuy"
            placeholder="请输入限购次数 0 不限制"
          /> -->
          <el-switch v-model.number="form.xgBuy" active-color="#13ce66" inactive-color="#F4F4F5"
            :active-value="form.xgBuy != 0 ? form.xgBuy : 1" :inactive-value="0"
            :active-text="form.xgBuy != 0 ? '请在下面输入限购次数   ' : ''">
          </el-switch>

          <el-input-number v-if="form.xgBuy != 0" v-model="form.xgBuy" controls-position="right" :min="0" />
        </el-form-item>
        <el-form-item label="今日限购次数" prop="fid">
          <!-- <el-input
            v-model="form.xgBuy"
            placeholder="请输入限购次数 0 不限制"
          /> -->
          <el-switch v-model.number="form.fid" active-color="#13ce66" inactive-color="#F4F4F5"
            :active-value="form.fid != 0 ? form.fid : 1" :inactive-value="0"
            :active-text="form.fid != 0 ? '请在下面输入今日限购次数' : ''">
          </el-switch>

          <el-input-number v-if="form.fid != 0" v-model="form.fid" controls-position="right" :min="0" />
        </el-form-item>
        <el-form-item label="全收阈值" prop="xgAll">
          <el-switch v-model.number="form.xgAll" active-color="#13ce66" inactive-color="#F4F4F5"
            :active-value="form.xgAll != 0 ? form.xgAll : 1" :inactive-value="0"
            :active-text="form.xgAll != 0 ? '请在下面输入抽几次开启全收' : ''">
          </el-switch>
          <el-input-number v-if="form.xgAll != 0" v-model="form.xgAll" controls-position="right" :min="0" />
          <!-- <el-input

            v-model="form.xgAll"
            placeholder="请输入抽几次开启全收 0不限制"
          /> -->
        </el-form-item>
        <el-form-item label="是否全收" prop="kgAll">
          <el-switch v-model.number="form.kgAll" active-color="#13ce66" inactive-color="#F4F4F5" :active-value="1"
            :inactive-value="0">
          </el-switch>
        </el-form-item>

        <el-form-item label="是否中赏记录排序" prop="kgAll">
          <el-switch v-model.number="form.sortType" active-color="#13ce66" inactive-color="#F4F4F5" :active-value="1"
            :inactive-value="0">
          </el-switch>
        </el-form-item>

        <el-form-item label="购买方式" prop="payType">
          <el-select v-model="form.payType" multiple placeholder="请选择购买方式">
            <el-option v-for="dict in dict.type.pay_type" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>

        <el-form-item v-if="if_menkan" label="流水支付门槛" prop="payType">
          <el-input-number v-model="form.menKan" controls-position="right" :min="0" />
        </el-form-item>

        <el-form-item label="产生积分" prop="ifJf">
          <el-switch v-model.number="form.ifJf" active-color="#13ce66" inactive-color="#F4F4F5" :active-value="1"
            :inactive-value="0">
          </el-switch>
        </el-form-item>

        <el-form-item label="产生流水" prop="ifLs">
          <el-switch v-model.number="form.ifLs" active-color="#13ce66" inactive-color="#F4F4F5" :active-value="1"
            :inactive-value="0">
          </el-switch>
        </el-form-item>

        <el-form-item label="审核显示" prop="status">
          <el-radio-group v-model.number="form.ifPublicShow">
            <el-radio :label="0">充值可见</el-radio>
            <el-radio :label="1">登录可见</el-radio>
            <el-radio :label="2">公开可见</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="串串乐" prop="ifJf">
          <el-input v-model="form.chuan" placeholder="请输入串串乐" />
        </el-form-item>

        <el-form-item label="空车" prop="ifLs">
          <el-input v-model="form.kongche" placeholder="请输入空车" />
        </el-form-item>
        <el-form-item label="是否区间" prop="ifLs">
          <el-switch v-model.number="form.ifInterval" active-color="#13ce66" inactive-color="#F4F4F5" :active-value="1"
            :inactive-value="0">
          </el-switch>
        </el-form-item>
        <el-form-item v-if="form.type == 0" label="是否可以锁箱" prop="ifCanLock">
          <!-- <el-input
            v-model="form.xgBuy"
            placeholder="请输入限购次数 0 不限制"
          /> -->
          <el-switch v-model.number="form.ifCanLock" active-color="#13ce66" inactive-color="#F4F4F5"
            :active-value="form.ifCanLock != 0 ? form.ifCanLock : 1" :inactive-value="0"
            :active-text="form.ifCanLock != 0 ? '请在下面输入锁箱门槛' : ''">
          </el-switch>

          <el-input-number v-if="form.ifCanLock != 0" v-model="form.minLocNum" controls-position="right" :min="0" />
        </el-form-item>
        <!-- <el-form-item label="是否区间" prop="ifLs">

          <el-input v-model="form.ifInterval" placeholder="请输入收集" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" :loading="up_end" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 快捷导入 -->
    <el-dialog title="快捷导入" :visible.sync="dialogVisible" width="50%" center :close-on-click-modal="false">
      <importForm @func="update" />
    </el-dialog>
  </div>
</template>

<script>
import {
  listGoods,
  getGoods,
  delGoods,
  addGoods,
  updateGoods,
  lockBox,
  paiBox,
  copyBox,
} from "@/api/yfs/box.js";
import { listFl } from "@/api/yfs/box_class.js";
import importForm from "@/components/importForm/put_box.vue";
import myAffix from "@/components/affix.vue"

import { update_status } from "@/api/czz/index.js";
export default {
  dicts: ["pay_type"],
  name: "Box_list",
  watch: {
    //监听支付方式
    "form.payType": function (val) {
      console.log(val);
      //判断数组是否有3
      if (val) {
        if (val.indexOf("3") != -1) {
          this.if_menkan = true;
        } else {
          this.if_menkan = false;
        }
      }
    },
  },
  data() {
    return {
      up_end: false,
      if_menkan: false,
      //是否打开快捷导入
      dialogVisible: false,

      inputVisible: false,
      inputValue: "",

      //盒子分类列表
      listFl: [],
      class_box: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品信息表格数据
      goodsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数

      queryParams: {
        isAsc: "desc", // 排序，asc／desc
        orderByColumn: "updateDate", // 排序，字段
        pageNum: 1,
        id: null,
        pageSize: 10,
        fid: null,
        title: null,
        imgurl: null,
        sort: null,
        status: null,
        price: null,
        isYu: null,
        arriveTime: null,
        type: null,
        stock: null,
        xgBuy: null,
        xgAll: null,
        kgAll: null,
        addtime: null,
        creator: null,
        createDate: null,

        pay_type: [],
        ifxg_btn_num: null,
        ifxg_btn_all: null,
        ifUserMade: null,
        ifPublicShow: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        type: [
          { required: true, message: "类型不能为空", trigger: "blur" },
        ],

        title: [
          { required: true, message: "商品名称不能为空", trigger: "blur" },
        ],
        imgurl: [
          { required: true, message: "商品封面图不能为空", trigger: "blur" },
        ],
        price: [
          {
            required: true,
            message: "价格不能为空",
            trigger: "blur",
          },
        ],
        stock: [
          {
            required: true,
            message: "套数不能为空",
            trigger: "blur",
          },
        ],
        payType: [
          {
            required: true,
            message: "购买方式不能为空",
            trigger: "change",
          },
        ],
        status: [
          {
            required: true,
            message: "上架方式不能为空",
            trigger: "blur",
          },
        ],
        // xgBuy: [
        //   {
        //     required: true,
        //     message: "限购次数 0 不限制不能为空",
        //     trigger: "blur",
        //   },
        // ],
        // xgAll: [
        //   {
        //     required: true,
        //     message: "抽几次开启全收 0不限制不能为空",
        //     trigger: "blur",
        //   },
        // ],
        // kgAll: [
        //   {
        //     required: true,
        //     message: "全收0关闭 1开启不能为空",
        //     trigger: "blur",
        //   },
        // ],
        addtime: [
          { required: true, message: "添加时间不能为空", trigger: "blur" },
        ],
      },
    };
  },
  components: {
    importForm, myAffix
  },

  created() {
    this.getList();
    this.getFlList();

    var _this = this;
    document.onkeydown = function (e) {
      let key = window.event.keyCode;
      if (key == 13) {
        _this.submitForm();
      }
    };
  },
  //过滤器
  filters: {
    //支付类型
    pay_type(val) {
      console.log(val);
    },
  },

  methods: {
    //复制盒子
    copyBox(data) {
      this.$modal.loading("正在复制盒子，请稍候...");
      copyBox({
        goodsId: data,
        type: 1,
      }).then((res) => {
        this.getList();

        this.$modal.closeLoading();
        this.$message({
          message: "复制成功",
          type: "success",
        });
      });
    },

    //盒子上锁、
    lockBox(id) {
      console.log(id.id);
      paiBox(id.id).then((res) => {
        this.$message.success("排位成功");
        console.log(res);
      });
      lockBox(id.id).then((res) => {
        this.$message.success("上锁成功");
        this.getList();
      });
    },

    //接收一键导入表单数据
    update(value) {
      console.log(value);
      this.dialogVisible = false;

      this.form = value;
      this.form.id = null;
    },

    //获取分类列表
    getFlList() {
      listFl().then((res) => {
        console.log(res);
        this.listFl = res.rows;
        console.log(this.listFl);

        this.listFl.forEach((item) => {
          this.class_box[item.id] = item.title;
        });

        this.listFl = this.listFl.map((item) => {
          return {
            id: item.id,
            title: item.title,
          };
        });
        console.log(this.class_box);
      });
    },

    /** 查询商品信息列表 */
    async getList() {
      this.loading = true;
      await listGoods(this.queryParams).then((response) => {
        this.goodsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });

      //过滤状态为3的数据
      this.goodsList = this.goodsList.filter((item) => {
        return item.status != 3;
      });

      this.goodsList.forEach((item, index) => {
        if (item.payType) {
          this.goodsList[index].payType =
            this.goodsList[index].payType.split(",");
        } else {
          item.payType = [];
        }
      });
      console.log(this.goodsList);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        fid: null,
        title: null,
        imgurl: null,
        sort: null,
        status: 2,
        price: null,
        isYu: null,
        arriveTime: null,
        type: 1,
        stock: null,
        xgBuy: null,
        xgAll: null,
        kgAll: null,
        addtime: null,
        creator: null,
        createDate: null,
        ifJf: null,
        ifLs: null,
        payType: [],
        menkan: null,
        sortType: 1,
        chuan: 0,
        kongche: 0,
        shouji: 0,
        ifPublicShow: 0
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.orderByColumn = "";
      this.queryParams.isAsc = "";
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加盒子信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getGoods(id).then((response) => {
        this.form = response.data;
        if (this.form.payType) {
          this.form.payType = this.form.payType.split(",");
        }
        // this.form.ifxg_buy = 0;
        this.open = true;
        this.title = "修改盒子信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.up_end = true;
          console.log(this.form.payType);
          this.form.payType = `${this.form.payType}`;
          if (this.form.id != null) {
            updateGoods(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.up_end = false;
              this.getList();
            });
          } else {
            this.form.creator = this.$store.getters.id;
            addGoods(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.up_end = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除商品信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delGoods(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/goods/export",
        {
          ...this.queryParams,
        },
        `goods_${new Date().getTime()}.xlsx`
      );
    },
    /** 添加商品 */
    handleEditTable(row) {
      const tableId = row.id + "-" + row.ifUserMade + "-" + row.price;
      const tableName = row.title;
      //   const params = { pageNum: this.queryParams.pageNum };
      console.log(tableId);
      if (row.ifUserMade == 1 && row.stock == null) {
        this.$modal.msgError("请先填写玩家自制库存");
        return;
      }

      this.$tab.openPage(
        "添加[" + tableName + "]盒子商品",
        "/yfs/add_good/index/" + tableId
      );
    },
    /** 查看商品 */
    handleLookTable(row) {
      const tableId = row.id;
      const tableName = row.title;
      //   const params = { pageNum: this.queryParams.pageNum };
      console.log(row);

      this.$tab.openPage(
        "查看[" + tableName + "]盒子所有商品",
        "/box/goods_xq/index/" + tableId
      );
    },

    /** 查看中奖区间 */
    handlequjian(row) {
      const tableId = row.id;
      const tableName = row.title;
      //   const params = { pageNum: this.queryParams.pageNum };
      console.log(row);

      this.$tab.openPage(
        "查看[" + tableName + "]盒子中奖区间",
        "/yfs/qujian/index/" + tableId
      );
    },

    //快捷导入
    importExcel() {
      this.dialogVisible = true;
      console.log("弹窗");
    },
    //排序
    dataListSortChangeHandle(data) {
      if (!data.order || !data.prop) {
        this.queryParams.orderByColumn = "";
        this.queryParams.isAsc = "";
        return false;
      }
      this.queryParams.isAsc = data.order.replace(/ending$/, "");
      this.queryParams.orderByColumn = data.prop
        .replace(/([A-Z])/g, "_$1")
        .toLowerCase();
      this.getList();
    },
  },
};
</script>
